package com.doubleblacktech.datamanager
{
	import flash.data.SQLConnection;
	import flash.events.SQLErrorEvent;
	import flash.filesystem.File;
	
	[Event(name="dataError", type="com.doubleblacktech.datamanager.FxADataError")]
	
	public class FxaQuery extends SQLConnection
	{
		public var myConnMan:FxAConnectionManager;
     	
     	private var _fxaSqlStatements:Array = [];
     	private var _fxaSQL:String;
    	private var _dataSource:String = null;
    	private var _fxaSqlStr:String = null;
		private var _dir:String = '';
		private var _standardDir:File = new File;

		private var currId:String = null;
		
		public function FxaQuery(isSync:Boolean=false) {
			super(isSync);
			
			myConnMan = FxAConnectionManager.getInstance();
		}
				
		private function dispatchError(event:SQLErrorEvent):void {
			var fxaErrorVO:FxADataErrorVO = new FxADataErrorVO;
			
            fxaErrorVO.errCode = event.error.code;
            fxaErrorVO.errOperation = event.error.operation;
            fxaErrorVO.errMessage = event.error.message;
            fxaErrorVO.errType = 'open';
            
            var fxaError:FxADataError = new FxADataError("dataError");
			fxaError.data = fxaErrorVO;
			
			dispatchEvent(fxaError);
		}
		
		//**************************************************************
		// Getters and Setters
		//**************************************************************
		[Inspectable(arrayType="com.doubleblacktech.datamanager.FxASqlStatement")]
		public function get fxaSqlStatements():Array {
        	return _fxaSqlStatements.slice(0);
    	}

		public function set fxaSqlStatements(value:Array):void {
        	var n:int;
        	var i:int;

        	_fxaSqlStatements = value.slice(0);
    	}
    	
		[Inspectable(defaultValue="userDirectory", 
			enumeration="applicationStorageDirectory,desktopDirectory,userDirectory,documentsDirectory", 
			category="Other", name="standardDir")]
		public function get standardDir():String {
			return _dir;
		}
		
		[Inspectable(defaultValue="applicationStorageDirectory", 
			enumeration="applicationStorageDirectory,desktopDirectory,userDirectory,documentsDirectory", 
			category="Other", name="standardDir")]
		public function set standardDir(value:String):void {
			_dir = value;
			_standardDir = File[value];
			
			myConnMan.dbPath = _standardDir;
		}
		
		public function get dataSource():String {
        	return _dataSource;
    	}

		public function set dataSource(value:String):void {
        	if (value != null){
        		if(value == "null" || value == ""){
        			_dataSource = null;
        		} else {
        			_dataSource = value;
        		}
			} else {
                _dataSource = null;
        	}
        	
        	myConnMan.dbSource = _dataSource;
		}
		// END: Getters and Setters ***********************************
    	
    	
		//**************************************************************
		// Event Handlers
		//**************************************************************
		
		// END: Event Handlers *****************************************
	}
}
